import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '编号（ID）',
    name: 'id',
    placeholder: '请输入编号（ID）'
  },
  {
    type: 'input' as Itype,
    label: '鸡舍编号',
    name: 'chickenHouseId',
    placeholder: '请输入鸡舍编号'
  },
  {
    type: 'input' as Itype,
    label: '鸡舍名',
    name: 'chickenHouseName',
    placeholder: '请输入鸡舍名'
  },
   {
    type: 'input' as Itype,
    label: '鸡舍负责人编号',
    name: 'houseResponsibleId',
    placeholder: '请输入鸡舍负责人编号'
  },
  
  {
    type: 'input' as Itype,
    label: '鸡舍负责人名称',
    name: 'houseResponsibleName',
    placeholder: '请输入鸡舍负责人名称'
  },
  {
    type: 'input' as Itype,
    label: '鸡舍负责人电话',
    name: 'houseResponsiblePhone',
    placeholder: '请输入鸡舍负责人电话'
  },
  {
    type: 'input' as Itype,
    label: '入舍时间',
    name: 'transferTime',
    placeholder: '请输入入舍时间'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false); props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <>
          <Button
            type="link"
            size="middle"
            onClick={() => {
              props.setisMoreSearchShow(true);props.setsearchMore(true);
            }}
          >
            高级检索
            <RightOutlined style={{ marginLeft: '1px' }} />
          </Button>
        </>
      )}
    </Space>
  );
};

export const SearchSelector = (props: any) => {
  const [searchID, setSearchID]: any = useState('chickenHouseName');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[0].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setSearchID(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          if (e === '') {
            http
              .get('/feed/chicken/chickenInHouseFarming/list/1/30')
              .then((res) => {
                props.dataSource(res.data.records);
              });
            return;
          }
          switch (searchID) {
            case 'chickenHouseName': {
              http(
                `/feed/chicken/chickenInHouseFarming/get/chickenHouseName/${e}`
              ).then((res) => {
                props.dataSource(res.data);
              });
              break;
            }
            case 'houseResponsibleName': {
              http(
                `/feed/chicken/chickenInHouseFarming/get/houseResponsibleName/${e}`
              ).then((res) => {
                props.dataSource(res.data);
              });
              break;
            }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '姓名', value: 'chickenHouseName', onClick: (e: any) => {} },
  {
    label: '鸡舍号码',
    value: 'houseResponsibleName',
    onClick: (e: any) => {}
  }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
